<script>
    function submitOnEnter(commandId, e)
    {
        var keycode;
        if (window.event) {
            keycode = window.event.keyCode;
        } else if (e) {
            keycode = e.which;
        } else  {
            return true;
        }
              
        if (keycode == 13) {
            document.getElementById(commandId).click();
            return false;
        } else {
            return true;
        }
    }
</script>

<%-- 
    Document   : nicks
    Created on : 19-oct-2008, 17:28:29
    Author     : org.@le

--%>

<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
<c:if test="${sessionBean.ejbSession.owner==null}" >
            <jsp:forward page="../login.jsp" />
        </c:if>
        <c:if test="${!sessionBean.ejbSession.owner.adminUser}" >
            <jsp:forward page="../user/homeUser.jsp" />
        </c:if>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <f:view>
            <h:panelGrid width="100%">
                <rich:toolBar style="position:absolute; top: 10px; left: 10px" width="300px">
                    <a href="/site/faces/admin/admin.jsp" >Admin panel</a> > 
                    <h:outputText value="Forum's flags" />
                </rich:toolBar>
            </h:panelGrid>
            <h1>Forum's flaged messages</h1>
            <h:form>
                <h:outputText value="There's no flaged messages." rendered="#{empty FlagsBean.flagedMessages}"/>
                <rich:dataTable rendered="#{!empty FlagsBean.flagedMessages}" id="sitesTable" columns="6" rows="50" value="#{FlagsBean.flagedMessages}" var="message" border="1" >
                    <rich:column>
                        <f:facet name="header">
                            <h:outputText value="Message" />
                        </f:facet>
                        <h:panelGrid  >
                            <h:outputText value="#{message.subject}" />
                        </h:panelGrid>
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">
                            <h:outputText value="Published by" />
                        </f:facet>
                        <h:panelGrid >
                            <h:outputText value="#{message.handle.name}" />
                        </h:panelGrid>
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">
                            <h:outputText value="Date" />
                        </f:facet>
                        <h:panelGrid >
                            <h:outputText value="#{message.creationDate}" >
                                <f:convertDateTime type="date" />
                            </h:outputText>
                        </h:panelGrid>
                    </rich:column>
                    
                    <rich:column>
                        <f:facet name="header">
                        </f:facet>
                        <h:panelGrid >
                            <h:commandButton id="add1" image="/images/search.png" >
                                <f:setPropertyActionListener target="#{FlagsBean.viewFlag}" value="#{true}" />
                                <f:setPropertyActionListener target="#{FlagsBean.message}" value="#{message}" />
                                <a4j:support event="onclick" reRender="panel" />
                            </h:commandButton>
                            <rich:toolTip for="add1" direction="bottom-right" >
                                View flagged message
                            </rich:toolTip>
                        </h:panelGrid>
                    </rich:column>
                </rich:dataTable>
                       <rich:datascroller for="sitesTable" maxPages="5" page="#{sessionBean.pagePostsUser}" />
            </h:form>
            <h:form id="form1">
                <rich:panel id="panel" style="border: 0px">
                    <h:messages id="mal1" globalOnly="true"/>
                    <div align="right" >
                        <h:commandButton rendered="#{FlagsBean.viewFlag}" id="save1" value="Remove flags" action="#{FlagsBean.removeFlags}" type="submit">
                            <f:setPropertyActionListener target="#{FlagsBean.viewFlag}" value="#{false}" />
                        </h:commandButton>
                        <h:commandButton rendered="#{FlagsBean.viewFlag}" id="save2" value="Remove flags & message" action="#{FlagsBean.removeFlagsMessage}" type="submit">
                            <f:setPropertyActionListener target="#{FlagsBean.viewFlag}" value="#{false}" />
                        </h:commandButton>
                        <h:commandButton rendered="#{FlagsBean.viewFlag}" id="cancel" value="Cancel" immediate="true">
                            <f:setPropertyActionListener target="#{FlagsBean.viewFlag}" value="#{false}" />
                        </h:commandButton>
                        
                    </div>
                    <rich:panel rendered="#{FlagsBean.viewFlag}" >
                        <h:panelGrid columns="2" >
                            <h:panelGrid columns="2" >
                                <h:outputText value="Subject: " />
                                <h:outputText value="#{FlagsBean.message.subject}" />
                                <h:outputText value="Published by: " />
                                <h:outputText value="#{FlagsBean.message.handle.name}" />
                                <h:outputText value="Date: " />
                                <h:outputText value="#{FlagsBean.message.creationDate}" >
                                    <f:convertDateTime type="date" dateStyle="long" timeStyle="long" />
                                </h:outputText>
                                <h:outputText value="Content: " />
                                <h:outputText value="#{FlagsBean.message.content}" />
                            </h:panelGrid>
                        </h:panelGrid>
                    </rich:panel>
                    <rich:panel rendered="#{FlagsBean.viewFlag}" >
                        <h:outputText value="Flags" />
                        <rich:dataTable columns="2" rows="20" value="#{FlagsBean.message.banderotas}" var="flag" border="1" >
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Published by" />
                                </f:facet>
                                <h:panelGrid >
                                    <h:outputText value="#{flag.user.email}" />
                                </h:panelGrid>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Date" />
                                </f:facet>
                                <h:panelGrid >
                                    <h:outputText value="#{flag.date}" >
                                        <f:convertDateTime type="date" />
                                    </h:outputText>
                                </h:panelGrid>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Reason" />
                                </f:facet>
                                <h:panelGrid >
                                    <h:outputText value="#{flag.reason}" style="color:red" />
                                </h:panelGrid>
                            </rich:column>
                        </rich:dataTable>
                    </rich:panel>
                </rich:panel>
            </h:form>
        </f:view>
    </body>
</html>
